﻿
//...............................................................

//------------upload file


function GenAttrachFile() {
    var countUploadControl = Number($("#CountUploadControl").val()) + 1;
    $("#CountUploadControl").val(countUploadControl); // Tăng biến đếm số uploadControl lên 1
    var khaiBaoUploadControl = "<span id='DivAttrachFile" + countUploadControl + "' style=\"padding-bottom:5px;\">"
        + "<input type=\"file\" name=\"UploadControl\" id=\"AttrachFile" + countUploadControl + "\" size=\"53px\""
        + " onkeydown='CheckFileSize(" + countUploadControl + ")'" + " />(file)"
        + "<img title='Xóa File đính kèm' style='cursor:pointer' src='/Content/ImagesAdmin/DeleteIcon.png' onclick='RemoveAttrachFile(" + countUploadControl + ")' />"
        + "<input type='text' id='DescriptionFile" + countUploadControl + "' name='DescriptionFile' size=\"47.5px\" />(mô tả)"
        + "<br/></span>";
    $("#TapTinDinhKemDiv").append(khaiBaoUploadControl);
}

function RemoveAttrachFile(uploadControlIndex) {
    $("#DivAttrachFile" + uploadControlIndex).remove();
}


//........................................................

function DisplayFileUpload(ListFileName, DuongDan, id, Controller, Action) {
    var DanhSachFileDaUpLoad = "";
    if (ListFileName != null) {
        var list = ListFileName.split("|");
        if (list.length > 0) {
            for (var i = 0; i < list.length; i++) {
                if (!IsEmpty(list[i])) {
                    DanhSachFileDaUpLoad += "<span id='file" + i + "'>"
                        + "<a target='_self' name='summary' href='/Download/DownloadFile?fileName="
                        + list[i].toString() + "&path=" + DuongDan + "' style='color: Blue;' >"
                        + list[i].toString() + "</a>&nbsp;";
                    if (!IsEmpty(Action)) {
                        DanhSachFileDaUpLoad += "<img title='Xóa File đính kèm' alt='Xóa File đính kèm' style='cursor:pointer' src='/Images/CrossDelete.png' onclick=\"javascript:DoDeleteAttachAjax("
                        + i + "," + id + ",'" + list[i] + "','" + Controller + "','" + Action + "');\" />;&nbsp&nbsp;"
                    }
                    DanhSachFileDaUpLoad += "</span>";
                }
            }
        }
    }
    document.getElementById("lstAttachments").innerHTML = "";
    $("#lstAttachments").append(DanhSachFileDaUpLoad);
}

function DisplayFileUploadIsDeleted(ListFileName, DuongDan) {
    var DanhSachFileDaUpLoad = "";
    if (ListFileName != null) {
        var list = ListFileName.split("|");
        if (list.length > 0) {
            for (var i = 0; i < list.length; i++) {
                if (!IsEmpty(list[i])) {
                    DanhSachFileDaUpLoad += "<span id='file" + i + "'>"
                + "<a target='_self' name='summary' href='/Download/DownloadFile?fileName="
                + list[i].toString() + "&path=" + DuongDan + "' style='color: Blue;' >"
                + list[i].toString() + "</a>&nbsp;;&nbsp&nbsp;"
                + "</span>";
                }
            }
        }
    }
    document.getElementById("lstAttachments").innerHTML = "";
    $("#lstAttachments").append(DanhSachFileDaUpLoad);
}

/*Delete attachment file ajax
=============================================================*/

function DoDeleteAttachAjax(item, id, filename, Controller, Action) {
    document.getElementById("XoaFileMessage").innerHTML = "";
    if (confirm("Bạn có thực sự muốn xóa file " + filename + " ?")) {
        var url = basePath + Controller + "/" + Action + "?id=" + id + "&filename=" + filename;
        $.getJSON(url, null, function (data) {
            if (data) {
                //Xoa thanh cong
                $("span#file" + item).remove();
                //document.getElementById("XoaFileMessage").innerHTML = "Xóa file thành công ! ";
            }
            else {
                document.getElementById("XoaFileMessage").innerHTML = "Xóa file thất bại ! ";
            }
        });
    }
}
/*End EventHandler*/